// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CResolvedItemList.
//   $Id$



#pragma once

class CResolvedItem;
//<summary>
//	wraps a list of resolved items, controlling the construction
//	and destruction of CResolvedItem objects.
//</summary>
class CResolvedItemList
{
public:
	CResolvedItemList(void);
	~CResolvedItemList(void);
	// creates and inserts a new item into the list.
	//<param name="pItemBefore">
	//	pointer to the item after which you wish the 
	//	new item to be appended.  0 for insert at end
	//</param>
	//<returns>
	//	returns the new item created, or 0 if an error occurred.
	//</returns>
	CResolvedItem * InsertNewItem(CResolvedItem * pItemBefore, long lId);

	// removes and deletes an item from the list and memory.
	//	<returns>
	//		true if successful,
	//		false if the item was not in the list
	//	</returns>
	//	<remarks>
	//		If false is returned, the object was not deleted.
	//	</remarks>
	bool RemoveItem(CResolvedItem * pItem);
	// for the purposes of resolving the value of a list, stores pointers to any selected items in the list
	HRESULT SelectItem(CResolvedItem * pItem);
	// removes an item from the selcted items list.
	//<returns>
	//	S_OK if the item was successfully removed from the
	//	selected items list, otherwise S_FALSE, indicating 
	//	that it was not in the list to begin with.
	//</returns>
	HRESULT DeselectItem(CResolvedItem * pItem);
	// Fills a given node pParentNode with the concatenated values of all selected items in this list.
	HRESULT GetSelectedValue(IXMLDOMNode* pParentNode);
private:
	//The actual store for resolved items.
	CTypedPtrList<CPtrList,CResolvedItem*> m_ResolvedItems;
	//a list of those items in this list with selected set to true.
	CTypedPtrList<CPtrList,CResolvedItem*> m_SelectedItems;
	//this list may be contained within another, this contains a pointer to
	//	the top list.
	CResolvedItemList * m_pTopList;
	CMapPtrToPtr m_mapItems;
public:
	// inspects the ResolvedItems, seeing if any match any of the nodes in the given list.
	void FindAndSelect(CTypedPtrList<CPtrList, IXMLDOMNode* >& lstNodes);
};
